<template>
    <div class="" id="tyqyqkItem">
        <div class="title-row">
            <div class="flex item-center">
                <div class="label-line"></div>
                <span class="title">取号情况</span>

            </div>
            <div class="line"></div>
        </div>
        <ul class="take-content">
            <li @click="onClickItem(item,index)" v-for="(item,index) in dataList" :key="index" class="take-li">
                <i class="circle"></i>
                <div class="cell-label">
                    <div class="text-over">
                        <span class="take-num">【{{item.rankNum}}号】</span>
                        <span class="db-num">{{item.handleInfoName}}</span>
                    </div>
                </div>
                <span class="take-time">{{item.pastTime}}</span>
            </li>
            <div v-if="!dataList.length" class="no-data">
                <img src="../../assets/no-data.png" alt="">
            </div>
        </ul>
    </div>
</template>

<script>
import { tyGetTakeNumList } from "../../config/api";
import { getDateStr, addScrollEvent, removeScrollEvent } from "../../utils";
import Pubsub from "../../utils/pubsub";

export default {
    data() {
        return {
            dataList: [],
            scrollFlag: false,
            totalPage: 0, //总页数
            request: {
                pageNum: 1,
                pageSize: 999
            }
        };
    },
    mounted() {
        this.getList();
        this.pubsub_token1 = Pubsub.subscribe("TAKE_NUM", () => {
            this.getList();
        });
        // addScrollEvent("tyqyqkItem",this.handleScroll);
    },
    destroyed() {
        this.timer && clearInterval(this.timer);
        this.pubsub_token1 && Pubsub.unsubscribe(this.pubsub_token1);

        // removeScrollEvent("tyqyqkItem");
    },
    methods: {
        /**
         * 点击取号情况
         */
        onClickItem(item, index) {
            if (index == 0) {
                let {
                    handleInfo,handleInfoName,handlePersonName,telNo,
                    handlePersonCardNum,createTime,rankNum,cardStartTime,cardEndTime} =item;
                let obj = {
                    rankNum,
                    takeTime: createTime,
                    telNo,
                    handleInfo,
                    handleInfoName,
                    handlePersonName,
                    handlePersonCardNum,
                    handlePersonStartTime:cardStartTime,
                    handlePersonEndTime:cardEndTime,
                    id: item.id
                };
                Pubsub.publish("showRegisterDialog", {
                    type: "tysl",
                    handleType: "workbench",
                    ...obj
                });
            }
        },
        /**
         * 获取取号情况
         */
        getList(r = {}) {
            tyGetTakeNumList(this.request).then((result = {}) => {
                let { rows } = result;
                this.scrollFlag = false;
                rows.map(item => {
                    item.pastTime = getDateStr(item.createTime);
                });
                this.dataList = rows;
                this.totalPage = result.totalPage;
                this.timer = setInterval(this.setPastTime, 1000 * 60);
            });
        },
        /**
         * 换算过去时间
         */
        setPastTime() {
            let tamp = new Date().getTime();
            this.dataList.map(item => {
                item.pastTime = getDateStr(item.createTime);
            });
        },
        handleScroll: function(h1, h2) {
            if (this.scrollFlag) {
                return;
            }
            if (h1 > h2) {
                this.scrollFlag = true;
                let { pageNum } = this.request;
                console.log(this.totalPage);
                if (pageNum < this.totalPage) {
                    ++this.request.pageNum;
                    this.getList();
                }
            }
        }
    }
};
</script>

<style lang = "scss" scoped>
@import "../../css/unifyAcceptWorkbench.scss";

.take-content {
    margin: 25px 0;
    height: 225px;
    overflow: auto;
    .take-li {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 14px;
        cursor: pointer;
        &:last-child {
            margin-bottom: 0;
        }
        font-size: 16px;
    }
    .circle {
        height: 4px;
        width: 4px;
        border-radius: 4px;
        background: #000;
        display: block;
        margin-right: 20px;
    }
    .take-num {
        color: #ffaa00;
    }
    .take-time {
        font-size: 18px;
        color: #ffaa00;
        span {
            font-size: 14px;
            color: #888888;
        }
    }
}
</style>